package com.db.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/createCaptcha")
public class CreateCaptchaController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        LineCaptcha captcha = CaptchaUtil.createLineCaptcha(100,50);
        String code = captcha.getCode();
        HttpSession session = request.getSession();
        session.setAttribute("captchaCode",code);
        captcha.write(response.getOutputStream());
    }
}
